using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace Nacos.ClientApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IConfiguration _configuration;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="configuration"></param> 
        public WeatherForecastController(ILogger<WeatherForecastController> logger, IConfiguration configuration)
        {
            _logger = logger;
            _configuration = configuration;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
        /// <summary>
        /// GetNacosConfig
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        [HttpGet("GetNacosConfig")]
        public IEnumerable<string> GetNacosConfig(string key)
        {
            var result = new List<string>();
            var str1 = _configuration.GetValue<string>("Secret:JWT");
            result.Add(str1);
            if(!string.IsNullOrEmpty(key)) {
                var keyval = _configuration.GetValue<string>(key);
                result.Add(keyval);
            }
            return result;
        }
    }
}